package org.spotem.model;

import javax.persistence.*;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

@Entity
@Table(name = "track")
public class TrackImpl implements Track {

    @Id
    private String key;

    @Column(name = "creation_date")
    private Date creationDate;

    @JoinColumn(name = "id_owner", nullable = false)
    @ManyToOne(fetch = FetchType.EAGER)
    private UserImpl owner;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "track")
//    @OrderBy(value = "time")
    private List<TrackPointImpl> points = new LinkedList<>();

    @Column
    private Boolean finished;

    @Override
    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    public UserImpl getOwner() {
        return owner;
    }

    public void setOwner(UserImpl owner) {
        this.owner = owner;
    }

    public List<TrackPointImpl> getPoints() {
        return points;
    }

    public void setPoints(List<TrackPointImpl> points) {
        this.points = points;
    }
}
